package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import com.laowang.common.utils.DateUtils;
import com.laowang.common.utils.MobileCheck;
import com.laowang.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.TbWpUserMapper;
import com.laowang.project.system.domain.TbWpUser;
import com.laowang.project.system.service.TbWpUserService;

/**
 * h5用户Service业务层处理
 *
 * @author laowang
 * @date 2023-02-10
 */
@Service
public class TbWpUserServiceImpl implements TbWpUserService {
    @Autowired
    private TbWpUserMapper tbWpUserMapper;

    /**
     * 查询h5用户
     *
     * @param id h5用户ID
     * @return h5用户
     */
    @Override
    public TbWpUser selectTbWpUserById(Integer id) {
        return tbWpUserMapper.selectTbWpUserById(id);
    }

    /**
     * 查询h5用户列表
     *
     * @param tbWpUser h5用户
     * @return h5用户
     */
    @Override
    public List<TbWpUser> selectTbWpUserList(TbWpUser tbWpUser) {
        return tbWpUserMapper.selectTbWpUserList(tbWpUser);
    }

    /**
     * 新增h5用户
     *
     * @param tbWpUser h5用户
     * @return 结果
     */
    @Override
    public int insertTbWpUser(TbWpUser tbWpUser) {
        tbWpUser.setCreateTime(DateUtils.getNowDate());
        String phone = tbWpUser.getPhone();
        if (StringUtils.isEmpty(phone)){
            throw new CustomException("爸爸手机号不能为空",400);
        }
        if (!MobileCheck.isMobile(phone)){
            throw new CustomException("爸爸手机号格式有误",400);
        }
        String mmPhone = tbWpUser.getMmPhone();
        if (StringUtils.isEmpty(mmPhone)){
            throw new CustomException("妈妈手机号不能为空",400);
        }
        if (!MobileCheck.isMobile(mmPhone)){
            throw new CustomException("妈妈手机号格式有误",400);
        }

        String nnPhone = tbWpUser.getNnPhone();
        if (!StringUtils.isEmpty(nnPhone) ){
            if (!MobileCheck.isMobile(nnPhone)){
                throw new CustomException("奶奶手机号格式有误",400);
            }
        }
        String yyPhone = tbWpUser.getYyPhone();
        if (!StringUtils.isEmpty(yyPhone) ){
            if (!MobileCheck.isMobile(yyPhone)){
                throw new CustomException("爷爷手机号格式有误",400);
            }
        }

        return tbWpUserMapper.insertTbWpUser(tbWpUser);
    }

    /**
     * 修改h5用户
     *
     * @param tbWpUser h5用户
     * @return 结果
     */
    @Override
    public int updateTbWpUser(TbWpUser tbWpUser) {
        return tbWpUserMapper.updateTbWpUser(tbWpUser);
    }

    /**
     * 批量删除h5用户
     *
     * @param ids 需要删除的h5用户ID
     * @return 结果
     */
    @Override
    public int deleteTbWpUserByIds(Long[] ids) {
        return tbWpUserMapper.deleteTbWpUserByIds(ids);
    }

    /**
     * 删除h5用户信息
     *
     * @param id h5用户ID
     * @return 结果
     */
    @Override
    public int deleteTbWpUserById(Long id) {
        return tbWpUserMapper.deleteTbWpUserById(id);
    }
}
